package svc

import (
	"go-zero_try/mall/order/api/internal/config"
	"go-zero_try/mall/order/api/internal/middleware"
	"go-zero_try/mall/order/rpc/pb/usercenter"
	"go-zero_try/mall/order/util"

	"github.com/go-redis/redis"
	"github.com/zeromicro/go-zero/rest"
	"github.com/zeromicro/go-zero/zrpc"
)

type ServiceContext struct {
	Config     config.Config
	UserClient usercenter.UserCenter
	Redis      *redis.Client
	UserCheck  rest.Middleware
}

func NewServiceContext(c config.Config) *ServiceContext {
	redis := util.NewRedis(c.Redis.Host, c.Redis.Password, c.Redis.Db)
	return &ServiceContext{
		Config:     c,
		UserClient: usercenter.NewUserCenter(zrpc.MustNewClient(c.UserConf)),
		Redis:      redis,
		UserCheck:  middleware.NewUserCheckMiddleware().Handle,
	}
}
